<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.7"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>qLibc: utilities/qsocket.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">qLibc
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.7 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('qsocket_8c.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">qsocket.c File Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Socket dandling APIs.  
<a href="#details">More...</a></p>

<p><a href="qsocket_8c_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a86e043367b6ba401408c64736192319d"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qsocket_8c.html#a86e043367b6ba401408c64736192319d">qsocket_open</a> (const char *hostname, int port, int timeoutms)</td></tr>
<tr class="memdesc:a86e043367b6ba401408c64736192319d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create a TCP socket for the remote host and port.  <br /></td></tr>
<tr class="separator:a86e043367b6ba401408c64736192319d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a536b1963c73ec5ace917a57ffed1f3cd"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qsocket_8c.html#a536b1963c73ec5ace917a57ffed1f3cd">qsocket_close</a> (int sockfd, int timeoutms)</td></tr>
<tr class="memdesc:a536b1963c73ec5ace917a57ffed1f3cd"><td class="mdescLeft">&#160;</td><td class="mdescRight">Close socket.  <br /></td></tr>
<tr class="separator:a536b1963c73ec5ace917a57ffed1f3cd"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4285c6dd3c52560f3d471f332f6558bc"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qsocket_8c.html#a4285c6dd3c52560f3d471f332f6558bc">qsocket_get_addr</a> (struct sockaddr_in *addr, const char *hostname, int port)</td></tr>
<tr class="memdesc:a4285c6dd3c52560f3d471f332f6558bc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Convert hostname to sockaddr_in structure.  <br /></td></tr>
<tr class="separator:a4285c6dd3c52560f3d471f332f6558bc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aefe8cc8f14190e19e81d9ec090007bd2"><td class="memItemLeft" align="right" valign="top">char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qsocket_8c.html#aefe8cc8f14190e19e81d9ec090007bd2">qsocket_get_localaddr</a> (char *buf, size_t bufsize)</td></tr>
<tr class="memdesc:aefe8cc8f14190e19e81d9ec090007bd2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return local IP address.  <br /></td></tr>
<tr class="separator:aefe8cc8f14190e19e81d9ec090007bd2"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Socket dandling APIs. </p>

<p class="definition">Definition in file <a class="el" href="qsocket_8c_source.html">qsocket.c</a>.</p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a86e043367b6ba401408c64736192319d" name="a86e043367b6ba401408c64736192319d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a86e043367b6ba401408c64736192319d">&#9670;&#160;</a></span>qsocket_open()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int qsocket_open </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>hostname</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>port</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>timeoutms</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Create a TCP socket for the remote host and port. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">hostname</td><td>remote hostname </td></tr>
    <tr><td class="paramname">port</td><td>remote port </td></tr>
    <tr><td class="paramname">timeoutms</td><td>wait timeout milliseconds. if set to negative value, wait indefinitely.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the new socket descriptor, or -1 in case of invalid hostname, -2 in case of socket creation failure, -3 in case of connection failure. </dd></dl>

<p class="definition">Definition at line <a class="el" href="qsocket_8c_source.html#l00065">65</a> of file <a class="el" href="qsocket_8c_source.html">qsocket.c</a>.</p>

</div>
</div>
<a id="a536b1963c73ec5ace917a57ffed1f3cd" name="a536b1963c73ec5ace917a57ffed1f3cd"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a536b1963c73ec5ace917a57ffed1f3cd">&#9670;&#160;</a></span>qsocket_close()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qsocket_close </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>sockfd</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>timeoutms</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Close socket. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">sockfd</td><td>socket descriptor </td></tr>
    <tr><td class="paramname">timeoutms</td><td>if timeoutms &gt;= 0, shut down write connection first then wait and throw out input stream data. set to -1 to close socket immediately.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true on success, or false if an error occurred. </dd></dl>

<p class="definition">Definition at line <a class="el" href="qsocket_8c_source.html#l00109">109</a> of file <a class="el" href="qsocket_8c_source.html">qsocket.c</a>.</p>

</div>
</div>
<a id="a4285c6dd3c52560f3d471f332f6558bc" name="a4285c6dd3c52560f3d471f332f6558bc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4285c6dd3c52560f3d471f332f6558bc">&#9670;&#160;</a></span>qsocket_get_addr()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qsocket_get_addr </td>
          <td>(</td>
          <td class="paramtype">struct sockaddr_in *&#160;</td>
          <td class="paramname"><em>addr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>hostname</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>port</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Convert hostname to sockaddr_in structure. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">addr</td><td>sockaddr_in structure pointer </td></tr>
    <tr><td class="paramname">hostname</td><td>IP string address or hostname </td></tr>
    <tr><td class="paramname">port</td><td>port number</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise returns false. </dd></dl>

<p class="definition">Definition at line <a class="el" href="qsocket_8c_source.html#l00135">135</a> of file <a class="el" href="qsocket_8c_source.html">qsocket.c</a>.</p>

</div>
</div>
<a id="aefe8cc8f14190e19e81d9ec090007bd2" name="aefe8cc8f14190e19e81d9ec090007bd2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aefe8cc8f14190e19e81d9ec090007bd2">&#9670;&#160;</a></span>qsocket_get_localaddr()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">char * qsocket_get_localaddr </td>
          <td>(</td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>buf</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>bufsize</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Return local IP address. </p>
<dl class="section return"><dt>Returns</dt><dd>malloced string pointer which contains IP address string if successful, otherwise returns NULL </dd></dl>

<p class="definition">Definition at line <a class="el" href="qsocket_8c_source.html#l00156">156</a> of file <a class="el" href="qsocket_8c_source.html">qsocket.c</a>.</p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_7b5d38f1875f1b693f62ca6a108a1129.html">utilities</a></li><li class="navelem"><a class="el" href="qsocket_8c.html">qsocket.c</a></li>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.7 </li>
  </ul>
</div>
</body>
</html>
